package app

import (
	"context"

	v1 "gitee.com/liangziyisheng/caas-platform-mc/api/app/v1"

	"gitee.com/liangziyisheng/caas-platform-mc/internal/service"

	"gitee.com/liangziyisheng/caas-platform-mc/utility/utils"
)

func (c *ControllerV1) Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) {
	in := &v1.AddInput{}
	// if req.Name != "" {
	// 	in.Name = req.Name
	// }
	// if req.Description != "" {
	// 	in.Description = req.Description
	// }
	// if req.Code != "" {
	// 	in.Code = req.Code
	// }
	utils.CopyStruc(*req, in)
	res = &v1.AddRes{}
	out, err := service.App().Add(ctx, in)
	if err != nil {
		return nil, err
	}
	res.Id = out.Id
	return res, nil
}
